/***************************
* 登陆、注册 初始化
****************************/

// 注册
$$(".login-screen #link_btnRegister").on("click", function () {
    $$(".login-screen #login").hide();
    $$(".login-screen #register").show();
});
// 登陆
$$(".login-screen #link_btnlogin").on("click", function () {
    $$(".login-screen #login").show();
    $$(".login-screen #register").hide();
});
// 初始化登陆
$$(".login-screen #btnLogin").on("click", function () {

    var username = $$(".login-screen #username").val();
    var password = $$(".login-screen #password").val();

    if (!hasOpenId("请使用微信登陆")) {
        return;
    }
    if (username == "" || password == "") {
        myApp.alert("账号密码不能为空");
        return;
    }

    var _content = JSON.stringify({
        type: 10,
        user: {
            PhoneNumber: username,
            Pwd: password
        }
    });

    $$.ajax({
        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
        data: { "content": _content },
        crossDomain: true,
        dataType: "json",
        async: false,
        success: function (data, status) {
            if (data && data.status == 0 && data.total > 0) {
                UpdateUserId(data.results.ID, "绑定成功！", "绑定失败！");
            }
            else {
                myApp.alert("绑定失败，请确认您的账号密码是否正确！");
            }
        },
        error: function (xhr, status) { }
    }); // end ajax
});
// 发送验证码
$$(".login-screen #btnSendCode").on("click", function () {

    var phone = $$(".login-screen #phone").val();

    if (!hasAccount("当前公众号错误") || !hasOpenId("请使用微信登陆")) {
        return;
    }
    if (phone == "") {
        myApp.alert("手机号不能为空");
        return;
    }
    else if (!/^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/.test(phone)) {
        myApp.alert("手机号格式不正确");
        return;
    }

    // 生成验证码
    var code = GetRandomStr();
    code = new Base64().encode(code);

    var conditionParm = {
        phone: phone,
        type: 1,
        code: GetRandomStr(),
    };

    $$.ajax({
        url: ISS_Constants.Url.const_user_send_verificcode,
        data: conditionParm,
        crossDomain: true,
        dataType: "json",
        async: false,
        success: function (data, status) {
            if (data && data.IsSuccess) {
                var count = 120;
                var countdown = setInterval(CountDown, 1000);
                $$(".login-screen #btnSendCode").attr("disabled", true);
                //$$(".login-screen #btnSendCode").addClass("btn-disabled");
                function CountDown() {
                    $$(".login-screen #btnSendCode").html("重新发送(" + count + ")");
                    if (count == 0) {
                        $$(".login-screen #btnSendCode").html("获取验证码").removeAttr("disabled");
                        //$$(".login-screen #btnSendCode").removeClass("btn-disabled");
                        clearInterval(countdown);
                    }
                    count--;
                }

                iss_localStorage.set("yuqing_code", code);
                myApp.alert("验证码发送成功！");
            }
            else {
                myApp.alert("验证码发送失败！");
            }
        },
        error: function (xhr, status) { }
    }); // end ajax

    // 获取随机数
    function GetRandomStr() {
        var code = "";
        for (var i = 0; i < 4; i++) {
            code += GetRandomNum(1, 10);
        }
        return code;
    }; // end
    // 获取随机数
    function GetRandomNum(Min, Max) {
        var Range = Max - Min;
        var Rand = Math.random();
        return (Min + Math.round(Rand * Range));
    }; // end
});
// 注册
$$(".login-screen #btnRegister").on("click", function () {

    var phone = $$(".login-screen #phone").val();
    var code = $$(".login-screen #code").val();

    if (!hasAccount("当前公众号错误") || !hasOpenId("请使用微信登陆")) {
        return;
    }
    if (phone == "") {
        myApp.alert("手机号不能为空");
        return;
    }
    if (code == "") {
        myApp.alert("验证码不能为空");
        return;
    }
    else if (code != new Base64().decode(iss_localStorage.get("yuqing_code"))) {
        myApp.alert("验证码不正确");
        return;
    }

    var base64 = new Base64();
    var pwd = base64.encode("111111");
    pwd = "111111";

    var _content = JSON.stringify({
        type: 11,
        user: {
            PhoneNumber: username,
            Pwd: password
        }
    });

    $$.ajax({
        url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
        data: { "content": _content },
        crossDomain: true,
        dataType: "json",
        async: false,
        success: function (data, status) {
            if (data && data.key == "success") {
                var id = data.ID;
                UpdateUserId(id, "注册成功！", "注册失败");
            }
            else {
                myApp.alert("注册失败！");
            }
        },
        error: function (xhr, status) { }
    }); // end ajax
});

//创建登录弹出层
function CheckPopLogin(callback) {
    if (!hasUserIdOther("请申请或绑定平台账号")) {
        var popupHTML = '<div class="popup popup-login login">' +
            '<div class="login-header">' +
            '<div class="login-title">登录</div>' +
            '<div id="btnClose" style="float:left;margin-left:15px;" class="close-popup">' +
            '<a href="#"><i class="icon icon-back">' +
            '</i><span style="margin-left:5px;font-size:1.2em;vertical-align: middle;">返回</span></a>' +
            '</div>' +
            '<div id="loginBtnRegiste" style="float:right;padding:0 15px;"><a href="#"><i></i><span style="margin-left:5px;font-size:1.2em;vertical-align: middle;">注册</span></a></div>' +
            '</div>' +
            '<div class="login-form">' +
            '<input type="text" id="phone" name="phone" placeholder="请输入手机号" />' +
            '<input type="password" style="display:none;" id="loginPwd" name="password" placeholder="请输入密码" />' +
            '<div id="securityCodeDiv" class="login-vercode">' +
            '<input type="text" id="vericode" name="number" placeholder="请输入验证码" />' +
            '<div class="login-vercode-btn">' +
            '<div class="vercode-timeout" style="display:none">59S</div>' +
            '<div class="vercode-btn" id="btnSendCode">获取验证码</div>' +
            '</div>' +
            '</div>' +
            '<div class="login-btn" id="btnRegister">登录</div>' +
            '<div class="login-bottom">' +
            '<div class="login-bottom-item login-switch" id="loginSwitch">密码登录</div>' +
            '<div class="login-bottom-item login-findpwd" id="loginFindPwd">找回密码</div>' +
            '</div>' +
            '<img src="../../assets/images/images-yuqing/picture/login_1.png" style="display:none" />' +
            '</div>' +
            '</div>';
        myApp.popup(popupHTML);
        // 0: 验证码登录，1：密码登录
        var loginType = 0;
        var randomCode;
        var timeout;
        var tmpUserInfo;
        var loginSuccessCallback = function (userInfo) {
            //缓存手机号
            iss_localStorage.set("yuqing_appUserId", userInfo.ID);
            iss_localStorage.set("yuqing_appUserName", userInfo.name);
            iss_localStorage.set("yuqing_appPhone", userInfo.phoneNumber);
            iss_localStorage.set("yuqing_appIdCard", userInfo.cardNo);
            //缓存用户信息
            iss_localStorage.set("yuqing_appNickName", userInfo.nickname);
            //同步WX_User 的 UserId
            var updateResult = UpdateUserId(userInfo.ID, "");
            //同步WAP_User 的信息
            var saveResult = SaveWapUser(userInfo);
            //更新积分

            // var userScore = CheckScore(userInfo.ID);

            //标识没有退出登录
            iss_localStorage.set("yuqing_isLoginOut", "false");
            //正常流程-----跳转页面
            if (callback) {
                //关闭登录窗口
                myApp.closeModal('.popup-login');
                callback();
            }
        };
        // 发送验证码
        var sendSecurityCode = function (phone) {
            randomCode = ISS.utils.randomInt(10000, 99999) + "";
            // var b = new Base64();
            // var content = b.encode(JSON.stringify({ "type": 19, "BookType": 1, "Phone": phone, "Code": randomCode }))
            // var md5 = hex_md5("CT" + ISS_Constants.serviceName.USERINFO + content + ISS_Constants.serviceKey.KEY).toUpperCase();
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                data: { "content": JSON.stringify({ "type": 19, "BookType": 1, "Phone": phone, "Code": randomCode }) },
                // url: ISS_Constants.Url.datacenter,
                // data: {
                //     "system": "CT",
                //     "serviceName": ISS_Constants.serviceName.USERINFO,
                //     "content": content,
                //     "key": md5
                // },
                crossDomain: true,
                method: "POST",
                dataType: "jsonp",
                success: function (data, status) {
                    myApp.hidePreloader();
                    console.log("data: " + data);
                    data = JSON.parse(data);
                    if (data.status != '0') {
                        myApp.alert("验证码发送失败.");
                        $$("#btnSendCode").removeAttr("disabled");
                    }
                    else {
                        myApp.alert("验证码已发送.");
                        //禁用获取验证码按钮
                        $$("#btnSendCode").attr("disabled", true);
                        var time = 60;
                        timeout = setInterval(function () {
                            --time;
                            if (time == 0) {
                                $$(".vercode-timeout").css("display", "none");
                                $$("#btnSendCode").removeAttr("disabled");
                                clearInterval(timeout);
                            }
                            else {
                                $$(".vercode-timeout").css("display", "inherit");
                                $$(".vercode-timeout").html(time + " S");
                            }
                        }, 1000);
                    }
                },
                error: function (xhr, status) {
                    $$("#btnSendCode").removeAttr("disabled");
                }
            });
        };
        // 注册
        $$('#loginBtnRegiste').on('click', function () {
            myApp.closeModal('.popup-login');
            clearInterval(timeout);
            loginCallback = callback;
            mainView.router.load({ 'url': '../../view-yuqing/user/findPwd1.html?type=reg' });
        });
        // 找回密码
        $$('#loginFindPwd').on('click', function () {
            myApp.closeModal('.popup-login');
            clearInterval(timeout);
            loginCallback = callback;
            mainView.router.load({ 'url': '../../view-yuqing/user/findPwd1.html' });
        });
        $$('#loginSwitch').on('click', function () {
            if (loginType == 0) {
                loginType = 1;
                $$('#securityCodeDiv').hide();
                $$('#loginPwd').show();
                $$('#loginSwitch').text("手机验证码登录");
            }
            else {
                loginType = 0;
                $$('#securityCodeDiv').show();
                $$('#loginPwd').hide();
                $$('#loginSwitch').text("密码登录");
            }
        });
        $$('#btnClose').on('click', function () {
            clearInterval(timeout);
            myApp.closeModal('.popup-login');
        })
        //发送验证码
        $$("#btnSendCode").on("click", function () {
            var phone = $$("#phone").val();
            //打开等待层
            myApp.showPreloader();
            $$("#btnSendCode").attr("disabled", true);

            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                data: { "content": JSON.stringify({ "type": 13, "user": { "PhoneNumber": phone } }) },
                crossDomain: true,
                method: "POST",
                dataType: "jsonp",
                success: function (data, status) {
                    data = JSON.parse(data);
                    if (data && data.status == '0' && data.results) {
                        tmpUserInfo = data.results;
                        sendSecurityCode(phone);
                    }
                    else {
                        myApp.hidePreloader();
                        myApp.alert("该用户不存在");
                        $$("#btnSendCode").removeAttr("disabled");
                    }
                },
                error: function (xhr, status) {
                    $$("#btnSendCode").removeAttr("disabled");
                }
            });
        })

        //登录
        $$("#btnRegister").on("click", function () {
            // var appAccount = iss_localStorage.get("yuqing_appAccount");
            var phone = $$("#phone").val();
            var vericode = $$("#vericode").val();
            var password = $$('#loginPwd').val();
            //验证手机号格式
            if (!ISS.utils.CheckPhone(phone)) {
                myApp.alert("请填写正确的手机号码");
                return;
            }
            //验证验证码输入
            if (loginType == 0 && (!vericode || vericode.length == 0)) {
                myApp.alert("请输入验证码");
                return;
            }
            if (loginType == 1 && (!password || password.length == 0)) {
                myApp.alert("请输入密码");
                return;
            }
            if (loginType == 0) {
                if (!vericode || vericode.length == 0) {
                    myApp.alert("请输入验证码");
                    return;
                }
                else if (vericode != randomCode) {
                    myApp.alert("验证码不正确");
                    return;
                }
            }
            //打开等待层
            myApp.showPreloader();

            if (loginType == 0)  // 验证码登录
            {
                myApp.hidePreloader();
                loginSuccessCallback(tmpUserInfo);
            }
            else                // 密码登录
            {
                $$.ajax({
                    url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                    data: { "content": JSON.stringify({ "type": 10, "user": { "PhoneNumber": phone, "Pwd": password } }) },
                    crossDomain: true,
                    method: "POST",
                    dataType: "jsonp",
                    success: function (data, status) {
                        myApp.hidePreloader();
                        data = JSON.parse(data);
                        if (data.status != '0') {
                            myApp.alert(data.message || "登录失败！");
                        }
                        else if (data && data.results && data.results.ID) {
                            loginSuccessCallback(data.results);
                        }
                        else {
                            myApp.alert("该用户不存在，请先注册！");
                        }
                    },
                    error: function (xhr, status) { }
                });
            }
        })

        return false;
    }
    else {
        if (callback) {
            callback();
        }
        return true;
    }
};


//创建登录弹出层
function CheckPopLogin_other(callback) {
    if (!hasUserIdOther("请申请或绑定平台账号")) {
        //拼接html
        // var popupHTML = '<div class="popup popup-login" style="background:#E6F0FF url(/Common/website/assets/images/common/user/login-bg.jpg) no-repeat;">' +
        //     '<form style="position:absolute;top:15%;left:5%;right:5%;">' +
        //     '<div class="login-screen-title">' +
        //     '登录</div>' +
        //     '<div class="card list-block">' +
        //     '<ul>' +
        //     '<li class="item-content">' +
        //     '<div class="item-inner">' +
        //     '<div class="item-input">' +
        //     '<input type="text" id="phone" name="phone" placeholder="请输入手机号">' +
        //     '</div>' +
        //     '</div>' +
        //     '</li>' +
        //     '<li class="item-content">' +
        //     '<div class="item-inner">' +
        //     '<div class="item-input">' +
        //     '<input type="text" id="vericode" name="vericode" placeholder="请输入验证码" style="float: left;width: 59%;">' +
        //     '<a href="#" id="btnSendCode" class="button button-fill color-blue" style="float: right;margin-top: 6px;width: 39%;">获取验证码</a>' +
        //     '</div>' +
        //     '</div>' +
        //     '</li>' +
        //     '</ul>' +
        //     '</div>' +
        //     '<div class="row">' +
        //     '<div class="col-50">' +
        //     '<a href="#" id="btnClose" class="button button-fill color-blue close-popup" style="height: 36px;' +
        //     'line-height: 36px;">取消</a>' +
        //     '</div>' +
        //     '<div class="col-50">' +
        //     '<a href="#" id="btnRegister" class="button button-raised button-fill color-orange"' +
        //     'style="height: 36px; line-height: 36px;">登录</a>' +
        //     '</div>' +
        //     '</div>' +
        //     '</form>' +
        //     '</div>';
        var popupHTML = '<div class="popup popup-login login">' +
            '<div class="login-header">' +
            '<div class="login-title">登录</div>' +
            '<div id="btnClose" style="float:left;margin-left:15px;" class="close-popup">' +
            '<a href="#"><i class="icon icon-back">' +
            '</i><span style="margin-left:5px;font-size:1.2em;vertical-align: middle;">返回</span></a>' +
            '</div>' +
            '</div>' +
            '<div class="login-form">' +
            '<input type="text" id="phone" name="phone" placeholder="请输入手机号" />' +
            '<div class="login-vercode">' +
            '<input type="text" id="vericode" name="number" placeholder="请输入验证码" />' +
            '<div class="login-vercode-btn">' +
            '<div class="vercode-timeout" style="display:none">59S</div>' +
            '<div class="vercode-btn" id="btnSendCode">获取验证码</div>' +
            '</div>' +
            '</div>' +
            '<div class="login-btn" id="btnRegister">登录</div>' +
            '</div>' +
            '<img src="../../assets/images/images-yuqing/picture/login_1.png" />' +
            '</div>';
        myApp.popup(popupHTML);

        var timeout;
        $$('#btnClose').on('click', function () {
            clearInterval(timeout);
            myApp.closeModal('.popup-login');
        })
        //发送验证码
        $$("#btnSendCode").on("click", function () {
            var appAccount = iss_localStorage.get("yuqing_appAccount");
            var phone = $$("#phone").val();

            if (appAccount == "") {
                appAccount = "b760689cb63a4a92834d6f14173bc293";
            }
            //打开等待层
            myApp.showPreloader();
            $$("#btnSendCode").attr("disabled", true);
            SendVerificationCode(appAccount, phone, function (result) {
                if (result == "-1") {
                    myApp.alert("请填写正确的手机号码");
                    $$("#btnSendCode").removeAttr("disabled");
                } else if (result == "0") {
                    myApp.alert("获取验证码失败");
                    $$("#btnSendCode").removeAttr("disabled");
                } else
                    if (result == "1") {
                        //禁用获取验证码按钮
                        $$("#btnSendCode").attr("disabled", true);
                        var time = 60;
                        timeout = setInterval(function () {
                            --time;
                            if (time == 0) {
                                $$(".vercode-timeout").css("display", "none");
                                $$("#btnSendCode").removeAttr("disabled");
                                clearInterval(timeout);
                            } else {
                                $$(".vercode-timeout").css("display", "inherit");
                                $$(".vercode-timeout").html(time + " S");
                            }
                        }, 1000);
                    }

                //关闭等待层
                myApp.hidePreloader();
            });
        })

        //登录
        $$("#btnRegister").on("click", function () {
            var appAccount = iss_localStorage.get("yuqing_appAccount");
            var phone = $$("#phone").val();
            var vericode = $$("#vericode").val();

            //验证手机号格式
            if (!ISS.utils.CheckPhone(phone)) {
                myApp.alert("请填写正确的手机号码");
                return;
            }
            //验证验证码输入
            if (vericode == "") {
                myApp.alert("请输入验证码");
                return;
            }

            //打开等待层
            myApp.showPreloader();
            //验证手机号+验证码
            var phoneNumber = CheckVerificationCode(appAccount, phone, vericode);
            //验证成功，根据手机号到门户获取用户信息
            if (phoneNumber && phoneNumber != null) {
                var userInfo = GetUserInfoByPhone(phoneNumber);
                //获取失败
                if (userInfo == null) {
                    //注册用户
                    userInfo = CreateUser(phoneNumber);
                }
                if (userInfo && userInfo != null && userInfo.ID != null && userInfo.ID != "") {
                    //缓存手机号
                    iss_localStorage.set("yuqing_appUserId", userInfo.ID);
                    iss_localStorage.set("yuqing_appUserName", userInfo.name);
                    iss_localStorage.set("yuqing_appPhone", userInfo.phoneNumber);
                    iss_localStorage.set("yuqing_appIdCard", userInfo.cardNo);
                    //缓存用户信息
                    iss_localStorage.set("yuqing_appNickName", userInfo.nickname);
                    //同步WX_User 的 UserId
                    var updateResult = UpdateUserId(userInfo.ID, "");
                    //同步WAP_User 的信息
                    var saveResult = SaveWapUser(userInfo);
                    //更新积分

                    // var userScore = CheckScore(userInfo.ID);

                    //标识没有退出登录
                    iss_localStorage.set("yuqing_isLoginOut", "false");
                    //正常流程-----跳转页面
                    if (callback) {
                        //关闭登录窗口
                        myApp.closeModal('.popup-login');
                        callback();
                    }
                } else {
                    myApp.alert("登录失败,请重新登录!");
                }
            } else {
                myApp.alert("验证码错误");
            }
            //关闭等待层
            myApp.hidePreloader();
        })

        return false;
    }
    else {

        return true;
    }
};


//创建登录弹出层
function CheckPopLogin_Menu(callback) {
    if (!hasUserId("请申请或绑定平台账号")) {
        // var popupHTML = '<div class="popup popup-login" style="background:#E6F0FF url(/Common/website/assets/images/common/user/login-bg.jpg) no-repeat;">' +
        //     '<form style="position:absolute;top:15%;left:5%;right:5%;">' +
        //     '<div class="login-screen-title">' +
        //     '登录</div>' +
        //     '<div class="card list-block">' +
        //     '<ul>' +
        //     '<li class="item-content">' +
        //     '<div class="item-inner">' +
        //     '<div class="item-input">' +
        //     '<input type="text" id="phone" name="phone" placeholder="请输入手机号">' +
        //     '</div>' +
        //     '</div>' +
        //     '</li>' +
        //     '<li class="item-content">' +
        //     '<div class="item-inner">' +
        //     '<div class="item-input">' +
        //     '<input type="text" id="vericode" name="vericode" placeholder="请输入验证码" style="float: left;width: 59%;">' +
        //     '<a href="#" id="btnSendCode" class="button button-fill color-blue" style="float: right;margin-top: 6px;width: 39%;">获取验证码</a>' +
        //     '</div>' +
        //     '</div>' +
        //     '</li>' +
        //     '</ul>' +
        //     '</div>' +
        //     '<div class="row">' +
        //     '<div class="col-50">' +
        //     '<a href="#" id="btnClose" class="button button-fill color-blue close-popup GoHome" style="height: 36px;' +
        //     'line-height: 36px;">取消</a>' +
        //     '</div>' +
        //     '<div class="col-50">' +
        //     '<a href="#" id="btnRegister" class="button button-raised button-fill color-orange"' +
        //     'style="height: 36px; line-height: 36px;">登录</a>' +
        //     '</div>' +
        //     '</div>' +
        //     '</form>' +
        //     '</div>';
        var popupHTML = '<div class="popup popup-login login">' +
            '<div class="login-header">' +
            '<div class="login-title">登录</div>' +
            '<div id="btnClose" style="float:left;margin-left:15px;" class="close-popup">' +
            '<a href="#"><i class="icon icon-back">' +
            '</i><span style="margin-left:5px;font-size:1.2em;vertical-align: middle;">返回</span></a>' +
            '</div>' +
            '</div>' +
            '<div class="login-form">' +
            '<input type="text" id="phone" name="phone" placeholder="请输入手机号" />' +
            '<div class="login-vercode">' +
            '<input type="text" id="vericode" name="number" placeholder="请输入验证码" />' +
            '<div class="login-vercode-btn">' +
            '<div class="vercode-timeout" style="display:none">59S</div>' +
            '<div class="vercode-btn" id="btnSendCode">获取验证码</div>' +
            '</div>' +
            '</div>' +
            '<div class="login-btn" id="btnRegister">登录</div>' +
            '</div>' +
            '<img src="../../assets/images/images-yuqing/picture/login_1.png" />' +
            '</div>';
        myApp.popup(popupHTML);

        var timeout;
        $$('#btnClose').on('click', function () {
            clearInterval(timeout);
            myApp.closeModal('.popup-login');
        })

        //发送验证码
        $$("#btnSendCode").on("click", function () {
            var appAccount = iss_localStorage.get("yuqing_appAccount");
            var phone = $$("#phone").val();

            if (appAccount == "") {
                appAccount = "b760689cb63a4a92834d6f14173bc293";
            }
            //打开等待层
            myApp.showPreloader();
            $$("#btnSendCode").attr("disabled", true);
            SendVerificationCode(appAccount, phone, function (result) {
                if (result == "-1") {
                    myApp.alert("请填写正确的手机号码");
                    $$("#btnSendCode").removeAttr("disabled");
                } else if (result == "0") {
                    myApp.alert("获取验证码失败");
                    $$("#btnSendCode").removeAttr("disabled");
                } else if (result == "1") {
                    //禁用获取验证码按钮
                    $$(".vercode-timeout").css("disabled", "true");
                    var time = 60;
                    timeout = setInterval(function () {
                        --time;
                        if (time == 0) {
                            $$(".vercode-timeout").css("display", "none");
                            $$("#btnSendCode").removeAttr("disabled");
                            clearInterval(timeout);
                        } else {
                            $$(".vercode-timeout").css("display", "inherit");
                            $$(".vercode-timeout").html(time + " S");
                        }
                    }, 1000);
                }
                //关闭等待层
                myApp.hidePreloader();
            });
        })

        //登录
        $$("#btnRegister").on("click", function () {
            var appAccount = iss_localStorage.get("yuqing_appAccount");
            var phone = $$("#phone").val();
            var vericode = $$("#vericode").val();

            //验证手机号格式
            if (!ISS.utils.CheckPhone(phone)) {
                myApp.alert("请填写正确的手机号码");
                return;
            }
            //验证验证码输入
            if (vericode == "") {
                myApp.alert("请输入验证码");
                return;
            }

            //打开等待层
            myApp.showPreloader();
            //验证手机号+验证码
            var phoneNumber = CheckVerificationCode(appAccount, phone, vericode);
            //验证成功，根据手机号到门户获取用户信息
            if (phoneNumber && phoneNumber != null) {
                var userInfo = GetUserInfoByPhone(phoneNumber);
                //获取失败
                if (userInfo == null) {
                    //注册用户
                    userInfo = CreateUser(phoneNumber);
                }
                if (userInfo && userInfo != null && userInfo.ID != null && userInfo.ID != "") {
                    //缓存手机号
                    iss_localStorage.set("yuqing_appUserId", userInfo.ID);
                    iss_localStorage.set("yuqing_appUserName", userInfo.name);
                    iss_localStorage.set("yuqing_appPhone", userInfo.phoneNumber);
                    iss_localStorage.set("yuqing_appIdCard", userInfo.cardNo);
                    //缓存用户信息
                    iss_localStorage.set("yuqing_appNickName", userInfo.nickname);

                    //同步WX_User 的 UserId
                    var updateResult = UpdateUserId(userInfo.ID, "");
                    //同步WAP_User 的信息
                    var saveResult = SaveWapUser(userInfo);
                    //更新积分

                    // var userScore = CheckScore(userInfo.ID);

                    //标识没有退出登录
                    iss_localStorage.set("yuqing_isLoginOut", "false");
                    //正常流程-----跳转页面
                    if (callback) {
                        //关闭登录窗口
                        myApp.closeModal('.popup-login');
                        callback();
                    }
                } else {
                    myApp.alert("登录失败,请重新登录!");
                }
            } else {
                myApp.alert("验证码错误");
            }
            //关闭等待层
            myApp.hidePreloader();
            //回调
            if (callback) {
                callback();
            }
        })

        //_menu的登录窗，取消就直接跳转到主界面
        $$(".GoHome").click(function () {
            window.location.href = _home;
        });
    }
    else {
        //回调
        if (callback) {
            callback();
        }
    };
};

var findPwdCallback_step1 = myApp.onPageInit('findPwdStep1', function (page) {
    var fromPage = page.fromPage ? page.fromPage.name : '';
    var fromUrl = page.fromPage ? page.fromPage.url : '';
    // 注册
    var isReg = (page.query && page.query.type == 'reg');
    if (isReg) {
        $$('#find-pwd-title-1').text('注册1/3');
    }
    $$('#to-find-pwd-step-2').on('click', function () {

        var phone = $$('#find-pwd-phone').val();
        if (!phone || phone.length == 0) {
            myApp.alert("请输入手机号码!");
            return;
        }

        var showNextPage = function () {
            var url = ""
            if (isReg) {
                url = '../../view-yuqing/user/findPwd2.html?phone=' + phone + "&fromPage=" + fromPage + "&isReg=true" + "&fromUrl=" + fromUrl;
            } else {
                url = '../../view-yuqing/user/findPwd2.html?phone=' + phone + "&fromPage=" + fromPage + "&fromUrl=" + fromUrl;
            }
            mainView.router.load({ url: url });
        };
        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
            data: { "content": JSON.stringify({ "type": 13, "user": { "PhoneNumber": phone } }) },
            crossDomain: true,
            method: "POST",
            dataType: "jsonp",
            success: function (data, status) {
                myApp.hidePreloader();
                data = JSON.parse(data);
                if (data && data.status == '0' && data.results) {
                    if (isReg) {
                        myApp.alert("您的手机号码已经注册过了，请登录。");
                    }
                    else {
                        showNextPage();
                    }
                }
                else {
                    if (isReg) {
                        showNextPage();
                    }
                    else {
                        myApp.alert("您还没有账号，请先申请注册！");
                    }
                }
            },
            error: function (xhr, status) {
                myApp.hidePreloader();
                showNextPage();
            }
        });
    });
});
var findPwdCallback_step2 = myApp.onPageInit('findPwdStep2', function (page) {
    var phone = page.query.phone;
    var randomCode;
    var timeout;
    // var isReg = (page.query && page.query.type == 'reg');
    var isReg = page.query.isReg;
    if (isReg == "true") {
        $$('#find-pwd-title-2').text('注册2/3');
    }
    myApp.onPageBack('findPwdStep2', function () {
        if (timeout) {
            clearTimeout(timeout);
        }
    });
    $$('#verify-phone-label').text('验证手机 ' + phone);
    // 下一步
    $$('#to-find-pwd-step-3').on('click', function () {
        var code = $$('#find-pwd-phone-security-code').val();
        if (!code || code.length == 0) {
            myApp.alert("请输入验证码!");
            return;
        }
        if (randomCode != code) {
            myApp.alert("验证码不正确.");
            return;
        }
        clearTimeout(timeout);
        $$(".vercode-timeout").css("display", "none");
        $$("#find-pwd-phone-get-security-code").removeAttr("disabled");

        var url = "";
        if (isReg == "true") {
            url = '../../view-yuqing/user/findPwd3.html?phone=' + phone + "&fromPage=" + page.query.fromPage + "&isReg=true" + "&fromUrl=" + page.query.fromUrl;
        } else {
            url = '../../view-yuqing/user/findPwd3.html?phone=' + phone + "&fromPage=" + page.query.fromPage + "&fromUrl=" + page.query.fromUrl;
        }
        mainView.router.load({ url: url });
    });

    // 获取验证码
    $$('#find-pwd-phone-get-security-code').on('click', function () {
        // 发送验证码
        myApp.showPreloader();
        randomCode = ISS.utils.randomInt(10000, 99999) + "";
        // var b = new Base64();
        // var content = b.encode(JSON.stringify({ "type": 19, "BookType": 1, "Phone": phone, "Code": randomCode }))
        // var md5 = hex_md5("CT" + ISS_Constants.serviceName.USERINFO + content + ISS_Constants.serviceKey.KEY).toUpperCase();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
            data: { "content": JSON.stringify({ "type": 19, "BookType": 1, "Phone": phone, "Code": randomCode }) },
            // url: ISS_Constants.Url.datacenter,
            // data: {
            //     "system": "CT",
            //     "serviceName": ISS_Constants.serviceName.USERINFO,
            //     "content": content,
            //     "key": md5
            // },
            crossDomain: true,
            method: "POST",
            dataType: "jsonp",
            success: function (data, status) {
                myApp.hidePreloader();
                console.log("data: " + data);
                data = JSON.parse(data);
                if (data.status != '0') {
                    myApp.alert("验证码发送失败.");
                    $$("#find-pwd-phone-get-security-code").removeAttr("disabled");
                }
                else {
                    myApp.alert("验证码已发送.");
                    //禁用获取验证码按钮
                    $$("#find-pwd-phone-get-security-code").attr("disabled", true);
                    var time = 60;
                    timeout = setInterval(function () {
                        --time;
                        if (time == 0) {
                            $$(".vercode-timeout").css("display", "none");
                            $$("#find-pwd-phone-get-security-code").removeAttr("disabled");
                            clearInterval(timeout);
                        }
                        else {
                            $$(".vercode-timeout").css("display", "inherit");
                            $$(".vercode-timeout").html(time + " S");
                        }
                    }, 1000);
                }
            },
            error: function (xhr, status) {
                $$("#find-pwd-phone-get-security-code").removeAttr("disabled");
            }
        });
    });
});

var findPwdCallback_step3 = myApp.onPageInit('findPwdStep3', function (page) {
    var phone = page.query.phone;
    var fromPage = page.query.fromPage;
    var fromUrl = page.query.fromUrl;
    var isReg = page.query.isReg;
    if (isReg == "true") {
        $$('#find-pwd-title-3').text('注册3/3');
        $$('#to-find-pwd-step-complted').text('注册');
    }
    $$('#to-find-pwd-step-complted').on('click', function () {
        var pwd = $$('#find-pwd-password').val();
        var confirmPwd = $$('#find-pwd-password-confirm').val();
        if (!pwd || pwd.length == 0) {
            myApp.alert("请输入密码!");
            return;
        }
        if (!confirmPwd || confirmPwd.length == 0) {
            myApp.alert("请输入确认密码!");
            return;
        }
        if (pwd != confirmPwd) {
            myApp.alert("两次密码输入不一致!");
            return;
        }
        var loginSuccessCallback = function (userInfo) {
            //缓存手机号
            iss_localStorage.set("yuqing_appUserId", userInfo.ID);
            iss_localStorage.set("yuqing_appUserName", userInfo.name);
            iss_localStorage.set("yuqing_appPhone", userInfo.phoneNumber);
            iss_localStorage.set("yuqing_appIdCard", userInfo.cardNo);
            //缓存用户信息
            iss_localStorage.set("yuqing_appNickName", userInfo.nickname);
            //同步WX_User 的 UserId
            var updateResult = UpdateUserId(userInfo.ID, "");

            //同步WAP_User 的信息
            var saveResult = SaveWapUser(userInfo);

            //标识没有退出登录
            iss_localStorage.set("yuqing_isLoginOut", "false");

            var okCallback = function () {
                mainView.router.back({ url: fromUrl, pageName: fromPage, force: true });
                if (loginCallback) {

                    loginCallback();
                }
            };

            if (isReg == "true") {
                myApp.alert("注册成功。", okCallback);
            }
            else {
                myApp.alert("修改密码成功。", okCallback);
            }
        };
        // 获取用户信息
        var loginAction = function () {
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                data: { "content": JSON.stringify({ "type": 13, "user": { "PhoneNumber": phone } }) },
                crossDomain: true,
                method: "POST",
                dataType: "jsonp",
                success: function (data, status) {
                    data = JSON.parse(data);
                    myApp.hidePreloader();
                    if (data && data.status == '0' && data.results) {
                        loginSuccessCallback(data.results);
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                }
            });
        };

        myApp.showPreloader();
        if (isReg == "true") {
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                data: { "content": JSON.stringify({ "type": 11, "user": { "PhoneNumber": phone, "Pwd": pwd } }) },
                crossDomain: true,
                timeout: 10000,
                method: "POST",
                dataType: "jsonp",
                success: function (data, status) {
                    data = JSON.parse(data);
                    if (data && data.status == '0' && data.results) {
                        loginAction();
                    }
                    else {
                        myApp.hidePreloader();
                        myApp.alert(data.message || '注册失败！');
                    }
                },
                complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                    if (status == 'timeout') {//超时,status还有success,error等值的情况
                        myApp.hidePreloader();
                        // ajaxTimeoutTest.abort();
                        myApp.alert("请求超时");
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('注册失败！');
                }
            });
        }
        else {
            $$.ajax({
                url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.USERINFO,
                data: { "content": JSON.stringify({ "type": 14, "user": { "PhoneNumber": phone, "Pwd": pwd } }) },
                crossDomain: true,
                timeout: 10000,
                method: "POST",
                dataType: "jsonp",
                success: function (data, status) {
                    data = JSON.parse(data);
                    if (data && data.status == '0' && data.results) {
                        loginAction();
                    }
                    else {
                        myApp.hidePreloader();
                        myApp.alert(data.message || '修改密码失败！');
                    }
                },
                complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                    if (status == 'timeout') {//超时,status还有success,error等值的情况
                        myApp.hidePreloader();
                        // ajaxTimeoutTest.abort();
                        alert("请求超时");
                    }
                },
                error: function (xhr, status) {
                    myApp.hidePreloader();
                    myApp.alert('修改密码失败！');
                }
            });
        }
    });
});